<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport('joomla.application.component.model');

/*
class TableKalenteriRyhma extends JTable
{
   
    var $id = null;
	var $nimi = null;
    
    function __construct( &$db ) {
        parent::__construct('#__kalenteriryhma', 'id', $db);
    }
}
*/
require_once JPATH_ADMINISTRATOR.DS.'components'.DS.'com_eventcalendar'.DS.'helpers'.DS.'database.php';

class EventcalendarsModelManageGroup extends JModel 
{
	function alustaDb()
	{
		$joku = new DatabaseHelper();
		$option = $joku->get('option');
		
		$db = & JDatabase::getInstance( $option );
		$this->setDBO($db);
	}

    function __construct() 
	{
		parent::__construct();
		$this->alustaDb();
    }

	  var $_data;
	  var $_calendars;
 
    /**
     * Returns the query
     * @return string The query to be used to retrieve the rows from the database
     */
    function _buildQuery($id)
    {
        $query = ' SELECT * '
            . ' FROM #__kalenteriryhma where id ='.$id;
        ;
        return $query;
    }
 
    /**
     *
     * @return array Array of objects containing the data from the database
     */
    function getGroup($id)
    {
        // Lets load the data if it doesn't already exist
        if (empty( $this->_data ))
        {
            $query = $this->_buildQuery($id);
            $this->_data = $this->_getList( $query );
        }
 
        return $this->_data;
    }
	
	function getCalendars($id)
	{
		$query = ' SELECT * FROM #__kalenteri where id in(select kalenteri_id from #__kalenteri_has_kalenteriryhma where kalenteriryhma_id ='.$id.' )';
        
		
		
		if (empty( $this->_calendars ))
        {
            $this->_calendars = $this->_getList( $query );
		
        }
	
	
 
        return $this->_calendars;
	
	}
	
	

	
	
}


?>